function getBoxList() {
    let boxList = {};
    $.ajax({
        async: false,
        type: "get",//type可以为post也可以为get
        url: "http://localhost:3000/policy",
        dataType: "json",//这里要注意如果后台返回的数据不是json格式，那么就会进入到error:function(data){}中
        success: function (data) {
            // console.log(data)
            // boxList=data;
            boxList = data
            // alert(data)
        },
        error: function (data) {
        }
    });
    return boxList;
}

let data = getBoxList();


let btn = document.getElementsByClassName("btn");
btn[1].style.backgroundColor = "#FE6C00";

document.getElementsByClassName('dynamic')[0].innerHTML = `
           <div class="Rotation"></div>
            <div class="dynamicContent" >
                <div class="boxbar">
                    <span class="boxbarLeft">就业动态</span>
                    <span class="boxbarRight">更多>></span>
                </div>
                <div id="list"></div>
           </div>
`;

function getListItem(data) {
    let listItem = '';
    data.forEach(function (item, index) {
        // console.log(item);
        if (index < 3) {
            listItem += `
                        <div class="more" >
                            <div class="list">
                                <img src="${item.imgSrc}" >
                            </div>
                            <div class="listContent">
                                ${item.content}
                            </div>
                        </div>
    `
        }
    });
    return listItem;
}

document.getElementById('list').innerHTML = getListItem(data.data);


// 轮播图----------------------------------

document.getElementsByClassName("Rotation")[0].innerHTML = `
<div id=banner>
<img src="${data.RotationImg.imgSrc1}" class="RotationImg " >
<img src="${data.RotationImg.imgSrc2}" class="RotationImg " >
<img src="${data.RotationImg.imgSrc3}" class="RotationImg " >
<img src="${data.RotationImg.imgSrc4}" class="RotationImg " >
<img src="${data.RotationImg.imgSrc5}" class="RotationImg " >
<div class="dots" id="dots">
    <span class="active"></span>
    <span ></span>
    <span ></span>
    <span ></span>
    <span ></span>
</div>
</div>
`


let num = 0,
    timer = null,
    pics = document.getElementById('banner').getElementsByTagName('img'),
    dots = document.getElementById('dots').getElementsByTagName('span');

function slide() {
    timer = setInterval(function () {
        num++;
        if (num >= 5) {
            num = 0;
        }
// 			console.log(index)
        // 切换图片
        changeImg(num);
    }, 1000);
}

function slideImg() {
    changeImg(num);
    slide();

    for (let i = 0; i < 5; i++) {
        // dots[i].id=i;
        dots[i].onclick = () => {
            num = i;
            changeImg(i);
            clearInterval(timer);
            slide();
        }

    }
}

slideImg();

function changeImg(num) {
    for (let i = 0; i < 5; i++) {
        pics[i].style.display = "none";
        dots[i].className = "";
    }
    // console.log(num);
    pics[num].style.display = "block";
    // console.log(pics[num].className);
    dots[num].className = "active";
}


// 政策解读---------------------------------

document.getElementsByClassName('policy')[0].innerHTML = getSupportList(data.policy);

function getSupportList(data) {
    let supportList = ``;
    data.forEach(function (item, i) {
        if (i < 4) {
            supportList += `
            <div class="policyListItem">
                <div class="policyListItemImg"><img src='${item.imgSrc}'></div>
                 <div class="policyContent">
                   <div class="policyTitle">${item.title}</div>
                        <span class="policyDetail">${item.content}</span>
                </div>
            </div>
            `
        }
    });
    return supportList;
};
